package com.example.myapplication




import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.myapplication.vieewholder

class adapter : RecyclerView.Adapter<vieewholder> {

    /** 保存数据的列表 */
    private val demoList: List<ItemBean>

    constructor(demoList: List<ItemBean>) {
        this.demoList = demoList
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): vieewholder {
        val view: View =
            LayoutInflater.from(parent.context).inflate(R.layout.weatheritem, parent, false)
        return vieewholder(view)
    }


    override fun onBindViewHolder(holder: vieewholder, position: Int) {
        val itemBean = demoList[position]

        itemBean.coverUrl?.let {
            holder.ivCover?.setImageResource(it)
        }

        itemBean.title?.let {
            holder.tvTitle.text = it
        }

        itemBean.content?.let {
            holder.tvContent.text = it
        }
    }


    override fun getItemCount(): Int {
        return demoList.size
    }
}
